package com.huawei.su;

import java.util.ArrayList;
import java.util.List;

public class BM23 {

    public static void main(String[] args) {
        //            1
        //      #           2
        //            3

        TreeNode root = new TreeNode(1, null, new TreeNode(2, new TreeNode(3), null));
        List<Integer> list = new ArrayList<>();
        preOrder(root, list);
        int[] ints = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            ints[i] = list.get(i);
        }

        System.out.println(list);
    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param root TreeNode类
     * @return int整型一维数组
     */
    public static int[] preorderTraversal(TreeNode root) {
        // write code here

        return null;
    }


    public static void preOrder(TreeNode biTree, List<Integer> list) {
        list.add(biTree.val);
        TreeNode leftTree = biTree.left;
        if (leftTree != null) {
            preOrder(leftTree, list);
        }
        TreeNode rightTree = biTree.right;
        if (rightTree != null) {
            preOrder(rightTree, list);
        }
    }
}
